package com.haois.mp.database.module.remote.service.impl;

import com.google.gson.Gson;
import com.haois.mp.database.util.HttpClientUtil;
import com.haois.mp.database.commom.CommonConstants;
import com.haois.mp.database.module.remote.service.ISysService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by RuiHaoZ on 2018/3/16 11:22
 */
@Service("iSysService")
public class SysServiceImpl implements ISysService {
    private static final Logger logger = LoggerFactory.getLogger(UserServiceImpl.class);

    @Value("${defined.database.server-url}")
    private String serverUrl;

    Gson gson = new Gson();

    @Override
    public Map getParameter(String accessToken) {
        String url = serverUrl.replace("/app","") + CommonConstants.SYS_HISLIDER;
        String response = HttpClientUtil.sendGet(url, new HashMap(), accessToken);
        Map result = gson.fromJson(response, Map.class);
        logger.debug("获取配置参数返回结果:{}", response);
        return result;
    }
    @Override
    public Map getParameter(String type, String accessToken) {
        Map params = new HashMap();
        params.put("type", type);
        String url = serverUrl.replace("/app","") + CommonConstants.SYS_PARAMETER_TYPE.replace("{type}",type);
        String response = HttpClientUtil.sendGet(url, new HashMap(), accessToken);
        Map result = gson.fromJson(response, Map.class);
        logger.debug("获取配置参数返回结果:{}", response);
        return result;
    }
}
